<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('流程版本信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form class="form-horizontal m" id="form-flowdefine-edit" th:object="${wflFlowdefine}">
                <input name="flowId" id="flowId" th:field="*{flowId}" type="hidden">
                <div class="form-group">
                    <label class="col-sm-1 control-label is-required">流程名称：</label>
                    <div class="col-sm-2">
                        <input name="flowName" th:field="*{flowName}" class="form-control" type="text" maxlength="32"
                               disabled>
                    </div>
                    <label class="col-sm-1 control-label is-required">流程类型：</label>
                    <div class="col-sm-2">
                        <select name="flowType" class="form-control m-b"
                                th:with="type=${@dict.getType('workflow_flow_type')}" disabled>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                    th:field="*{flowType}"></option>
                        </select>
                    </div>
                    <label class="col-sm-1 control-label is-required">启用版本号：</label>
                    <div class="col-sm-2">
                        <input name="curreVersion" th:field="*{curreVersion}" class="form-control" type="text" disabled>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label is-required">最新版本：</label>
                    <div class="col-sm-2">
                        <input name="newVersion" th:field="*{newVersion}" class="form-control" type="text" disabled>
                    </div>
                    <label class="col-sm-1 control-label is-required">流程状态：</label>
                    <div class="col-sm-2">
                        <select name="sts" class="form-control m-b" th:with="type=${@dict.getType('workflowsts')}"
                                disabled>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                    th:field="*{sts}"></option>
                        </select>
                    </div>
                    <label class="col-sm-1 control-label is-required">配置状态：</label>
                    <div class="col-sm-2">
                        <select name="flowProgress" class="form-control m-b"
                                th:with="type=${@dict.getType('flow_sts')}" disabled>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                    th:field="*{flowProgress}"></option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label is-required">流程说明：</label>
                    <div class="col-sm-8">
                        <textarea name="flowDesc" class="form-control" disabled>[[*{flowDesc}]]</textarea>
                    </div>
                </div>


            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()" shiro:hasPermission="workflow:flowdefine:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-info multiple disabled" onclick="copy()" shiro:hasPermission="workflow:flowdefine:add">
                <i class="fa fa-copy"></i> 复制
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="workflow:flowdefine:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="workflow:flowdefine:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="workflow:flowdefine:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="flowversion-table" data-auto-refresh="true" data-auto-refresh-interval="10"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-table-auto-refresh-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('workflow:flowdefine:edit')}]];
    var removeFlag = [[${@permission.hasPermi('workflow:flowdefine:remove')}]];
    var flowProgressDatas = [[${@dict.getType('flow_progress')}]];
    var stsDatas = [[${@dict.getType('workflowsts')}]];
    var prefix = ctx + "workflow/flowversion";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            id: "flowversion-table",
            modalName: "流程版本信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'versionId',
                    title: '版本号'
                },
                {
                    field: 'flowId',
                    title: '流程号'
                },
                {
                    field: 'flowProgress',
                    title: '配置进度',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(flowProgressDatas, value);
                    }
                },
                {
                    field: 'upTime',
                    title: '发布时间'
                },
                {
                    field: 'sts',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.versionId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.versionId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*新增流程版本*/
    function add() {
        var flowId = $("#flowId").val();
        var url = prefix + '/add/' + flowId;
        $.modal.openTab("流程版本配置", url);
        $.modal.close();
    }

    /* 复制 */
    function copy() {
        $.modal.confirm("确认要复制为新版本吗？", function () {
            $.operate.post(ctx + "workflow/flowversion/copy", {
                "flowId": $("#flowId").val(),
                "versionId": $.table.selectColumns('versionId')
            });
            $("#flowversion-table").bootstrapTable('refresh');
        })
    }

    /*配置流程版本信息*/
    function edit(versionId) {
        var url = prefix + '/edit/' + versionId;
        $.modal.openTab("流程版本配置", url);
    }

    /* 版本状态显示 */
    function statusTools(row) {
        if (row.sts == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="stsEnable(\'' + row.flowId + '\',\'' + row.versionId + '\',\'' + row.flowProgress + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="stsDisable(\'' + row.flowId + '\',\'' + row.versionId + '\')"></i> ';
        }
    }


    /* 版本状态启用 */
    function stsEnable(flowId, versionId, flowProgress) {
        $("#flowversion-table").bootstrapTable('refresh');
        if (flowProgress != 6) {
            $.modal.alertWarning("当前版本未完成配置，不能启用！");
            return;
        }
        $.modal.confirm("启用当前版本会自动停用其他版本，确认要启用吗？", function () {
            $.operate.post(ctx + "workflow/flowversion/changeSts", {
                "flowId": flowId,
                "versionId": versionId,
                "sts": "1"
            });
            $.table.search();
        })
    }

    /* 版本状态停用 */
    function stsDisable(flowId, versionId) {
        $.modal.confirm("确认要停用当前版本吗？", function () {
            $.operate.post(ctx + "workflow/flowversion/changeSts", {
                "flowId": flowId,
                "versionId": versionId,
                "sts": "0"
            });
            $.table.search();
        })

    }
</script>
</body>
</html>